﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace EmailMatching
{
    class EmailMatch
    {
        static void Main()
        {
            string text = "joe joe@home a@b.c joe@ho-me.com joe.bob@home.com joe-bob[at]home.com joe@his.home.com joe@his.home.place" +
            "joe@home.org joe@joebob.name joe.@bob.com .joe@bob.com joe<>bob@bob.come joe&bob@bob.com ~joe@bob.com" +
            "joe$@bob.com joe+bob@bob.com o'reilly@there.com";
            string pattern = @"\b(([a-z][a-z0-9]*)@([a-z0-9]+\-?[a-z0-9]+)(\.[a-z]+)+)\b";
            Regex regx = new Regex(pattern);
            MatchCollection matches = regx.Matches(text);
            foreach (Match match in matches)
            {
                Console.WriteLine(match);
            }
        }
    }
}
